package app.auto.runner.base.ui;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import app.auto.AndroidInstance;
import app.auto.runner.base.intf.FunCallback;

public class TextViewBuilder extends AndroidInstance {
    private String text = "+";
    //    private int sizeValue = 18;
    private int sizeValue = 20;

    private int width = -1;
    private int height = 55;
    private FunCallback clickrun;
    private int gravity;
    private int inttextcolor;
    private String stringtextcolor;
    private int padding;

    public TextViewBuilder setText(String text) {
        this.text = text;
        return this;
    }

    public TextViewBuilder setSizeValue(int sizeValue) {
        this.sizeValue = sizeValue;
        return this;

    }

    public TextViewBuilder setWidth(int width) {
        this.width = width;
        return this;

    }

    public TextViewBuilder setHeight(int height) {
        this.height = height;
        return this;
    }

    public TextViewBuilder newTextBuilder() {

        return this;
    }

    TextView tv;

    public TextViewBuilder setResTextcolor(String stringtextcolor) {
        this.stringtextcolor = stringtextcolor;
        return this;
    }

    public TextViewBuilder setResTextcolor(int textcolor) {
        this.inttextcolor = textcolor;
        return this;
    }

    @SuppressLint("NewApi")
    public TextView get() {
        tv = new TextView(getContext());
        tv.setText(text);
        if (inttextcolor != 0) {
            tv.setTextColor(getContext().getColor(inttextcolor));
        } else if (stringtextcolor != null) {
            tv.setTextColor(Color.parseColor(stringtextcolor));
        }
        tv.setTextSize(sizeValue);
        tv.setGravity(gravity == 0 ? Gravity.CENTER : gravity);
        tv.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height));
        tv.setPadding(padding, padding, padding, padding);
        if (clickrun != null) {
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickrun.onCallback(v, null);
                }
            });
        }
        return tv;
    }

    @Override
    public AndroidInstance use(Object mp, Object... p) {
        return null;
    }

    public TextViewBuilder setOnClick(FunCallback funCallback) {
        this.clickrun = funCallback;
        return this;
    }

    public TextViewBuilder setGravity(int gravity) {
        this.gravity = gravity;
        return this;
    }

    public TextViewBuilder setPadding(int padding) {
        this.padding = padding;
        return this;
    }
}
